#include <iostream>
#include <functional>

using std::cout;
using std::endl;
using std::bind;
using std::function;

class Example
{
public:
    int add(int x, int y)
    {
        cout << "int Example::add(int, int)" << endl;
        return x + y;
    }
};

void test()
{
    Example ex;
    auto f = bind(&Example::add, &ex, 100, 200);
    cout << "f() = " << f() << endl;

    cout << endl;
    auto f2 = bind(&Example::add, ex, 111, 222);
    cout << "f2() = " << f2() << endl;

    cout << endl;
    using namespace std::placeholders;
    auto f3 = bind(&Example::add, _1, 123, 456);
    cout << "f3(&ex) = " << f3(&ex) << endl;
    cout << "f3(ex) = " << f3(ex) << endl;

    cout << endl;
    function<int(Example *)> f4 = bind(&Example::add, _1, 222, 333);
    cout << "f4(&ex) = " << f4(&ex) << endl;

    cout << endl;
    function<int(Example &)> f5 = bind(&Example::add, _1, 222, 333);
    cout << "f5(ex) = " << f5(ex) << endl;

    cout << endl;
    function<int(Example )> f6 = bind(&Example::add, _1, 222, 333);
    cout << "f6(ex) = " << f6(ex) << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

